This routine is the heart of the script, without it the handler wouldn't
work very well at all.
What it does is create a list of the archive contents using the list
command of the various archivers, a separate program called ArcDirList then
reformats this output into something a bit easier and quicker for the script
to understand.
The script works from this list when you change directories, when you add
or delete files from the archive a new list has to be generated to keep the
lister display up to date.
1arclist:
2 lister set handle busy on
3 lister clear handle
4 lister set handle title getcatstr(1,'Listing archive...')
5 lister set handle path arcfile'/'arcsubdir
6 lister refresh handle full
7
8 if ~exists(arcfile) then do
9 call displayerror(getcatstr(22,'Error: archive not found'))
10 return
11 end
12
13 if ~exists('T:ArcDir.list'handle) then do
14 select
15 when arctype = 'LHA' then
16 address command 'LhA >T:ArcDir.list'handle 'vv -N -X -Qw -Qo "'arcfile'"'
17 when arctype = 'LZX' then
18 address command 'LZX >T:ArcDir.list'handle 'v -X0 --' lzxkludge(patch(arcfile,0))
19 end
20 if rc > 0 then
21 call displayerror(getcatstr(2,'Error while listing archive.'))
22 end
23
24 oldcurrent = pragma('d')
25 call pragma('d','DOpus5:C')
26 address command 'ArcDirList >T:ArcDir.list'handle'@ T:ArcDir.list'handle '"'patchstar(arcsubdir)'"'
27 call pragma('d',oldcurrent)
28
29 if ~open('tempfile','T:ArcDir.list'handle'@','r') then do
30 call displayerror(getcatstr(24,'ArcDirList not found!'))
31 return
32 end
33 thisline = readln('tempfile')
34 do while thisline ~= ''
35 lister add handle thisline
36 thisline = readln('tempfile')
37 end
38 call close('tempfile')
39 call delete('T:ArcDir.list'handle'@')
40
41 cuthere = lastpos('/',arcfile)
42 if cuthere = 0 then
43 cuthere = lastpos(':',arcfile)
44 arcname = substr(arcfile,cuthere + 1)
45 lister set handle title 'ArcDir:' arcname
46 lister refresh handle full
47 return
Line:
1 Sub-routine label.
2 - 6 Set the state of the lister to busy, clear the lister display, change
the titlebar to say 'Listing archive...', set the path gadget to the
path within the archive and refresh the lister display so we see all
these changes.
8 - 11 Check to see if the archive exists, if it doesn't return a nasty
message translating through getcatstr if necessary.
13 - 19 If an archive contents list doesn't currently exist, we use the
appropriate archiver to generate another one.
20 - 22 If there was an error listing the archive, tell the user.
24 - 27 Get the current directory, change directory to DOpus5:C so we can run
ArcDirList to format the output from the archivers in lines 13-19.
Then change back to the directory we were originally in.
29 - 32 We try to open the reformatted archive contents list, if we can't we
display an error message and return.
33 - 37 We read a line of the file then enter a DO loop until there is
nothing more to be read from the file. We add the line we read
initially to the lister display, then read another, add it, read
another, and so on until all entries have been read and added.
38 - 39 Close the file and delete the temporary file.
41 - 45 Here we look for a '/' or a ':' in the arcfile variable, when we find
it we set arcname to everything to the left of it and then set the
titlebar to 'ArcDir:' plus the archive name.
46 Refresh the lister display so we see all the entries and titlebar
changes.
47 Return to the calling function.
|